package com.suning.sawp.service.impl.oga.bi.support;

import org.joda.time.DateTimeConstants;
import org.joda.time.LocalDate;

import com.suning.sawp.dto.oga.bi.SimpleRange;

/**
 * 时间范围工具类
 * 
 * @author 13071602
 *
 */
public final class SimpleRanges {
    private SimpleRanges() {

    }

    public static SimpleRange<String> day(LocalDate localDate, String pattern) {
        return new SimpleRange<String>(localDate.toString(pattern), localDate.toString(pattern));
    }

    public static SimpleRange<String> week(LocalDate localDate, String pattern) {
        return new SimpleRange<String>(localDate.withDayOfWeek(DateTimeConstants.MONDAY).toString(pattern),
                localDate.withDayOfWeek(DateTimeConstants.SUNDAY).toString(pattern));
    }

    public static SimpleRange<LocalDate> monthWithLocalDate(LocalDate localDate) {
        return new SimpleRange<LocalDate>(localDate.withDayOfMonth(1),
                localDate.withDayOfMonth(localDate.dayOfMonth().getMaximumValue()));
    }

    public static SimpleRange<String> month(LocalDate localDate, String pattern) {
        SimpleRange<LocalDate> range = monthWithLocalDate(localDate);
        return new SimpleRange<String>(range.getLowerBound().toString(pattern),
                range.getUpperBound().toString(pattern));
    }

    /**
     * 
     * @param localDate 当月截止日期
     * @return
     */
    public static SimpleRange<String> monthToday(LocalDate localDate, String pattern) {
        return new SimpleRange<String>(localDate.withDayOfMonth(1).toString(pattern), localDate.toString(pattern));
    }

}
